#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include "conio.h"

using namespace std;

struct Box
{
	int a,b,c;

	friend istream& operator>>(istream &in, Box &b);

	bool operator< (const Box &box)
	{
		if (a < box.a && b < box.b && c < box.c)
			return true;
		else
			return false;
	}
};

istream& operator>>(istream &in, Box &b)
{
	in >> b.a >> b.b >> b.c;
	return in;
}

int find_max_number_of_folded_boxes(vector<Box> boxes) 
{
	vector<int> folds(boxes.size(), 1);

	for (int i_box = 0; i_box < static_cast<int>(boxes.size()); ++i_box)
	{
		for (int i_box_prev = i_box - 1; i_box_prev >= 0; --i_box_prev)
		{
			if (boxes[i_box_prev] < boxes[i_box] && folds[i_box] <= folds[i_box_prev])
			{
				folds[i_box] = folds[i_box_prev] + 1;
			}
		}
	}

	return *max_element(folds.begin(), folds.end());
}

void main()
{
	int n_boxes;
	cout << "enter number of boxes:" << endl;
	cin >> n_boxes;

	vector<Box> boxes(n_boxes);
	cout << "enter boxes:" << endl;
	for (int i_box = 0; i_box < n_boxes; i_box++)
	{
		cin >> boxes[i_box];
	}
	
	cout << "Max number of folded boxes = " << find_max_number_of_folded_boxes(boxes) << endl;
	_getch();
}